define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {

    var Controller = {
        app: function () {

            //新增
            $(document).on("click", "#appAdd", function () {
                Fast.api.open('/index/app/add', '新增应用');
            });



        },
        add: function () {

            $(document).on("click", ".submit", function () {
                var title = $("#appName").val();
                var letter = $("#appLetter").val();
                if(letter.length<3)
                {
                    Fast.api.msg('简写大于3个字符');
                    return false;
                }
                var desc = $("#appDesc").val();
                var post = {
                    title:title,
                    letter:letter,
                    desc:desc,
                };
                $.post("app/save",post,function(ret){
                    if(ret.code == 1)
                    {
                        layer.alert('创建成功', {icon: 1});
                        Fast.api.close();
                        parent.location.reload();

                    }
                    else
                    {
                        Fast.api.msg(ret.msg);
                        return false;
                    }


                });

            });

        },
        live: function () {

            //新增
            $(document).on("click", "#liveAdd", function () {
                var id = $(this).data('id');
                Fast.api.open('/index/app/live_add?id='+id, '新增直播通道');
            });

            $(document).on("click", ".live_url", function () {
                var url = $(this).data('url');
                var title = $(this).data('title');
                Fast.api.open(url, '查看'+title+'推流/拉流地址');

            });
            $(document).on("click", ".live_play", function () {
                var url = $(this).data('url');
                var title = $(this).data('title');
                Fast.api.open(url, '查看'+title+'直播');

            });

        },
        live_add: function () {

            $(document).on("click", ".submit", function () {
                var app_id = $("#appId").val();
                var title = $("#liveName").val();
                var server = $("#liveSserver").val();

                var post = {
                    app_id:app_id,
                    title:title,
                    server:server,
                };
                $.post("app/live_save",post,function(ret){
                    if(ret.code == 1)
                    {
                        layer.alert('直播创建成功', {icon: 1});
                        Fast.api.close();
                        parent.location.reload();

                    }
                    else
                    {
                        Fast.api.msg(ret.msg);
                        return false;
                    }
                });

            });

        },

    };
    return Controller;
});